<?php
class CorpInquriesController extends AppController {

	var $name = 'CorpInquries';

   	function index() {
		$this->CorpInqury->recursive = 0;
		$this->set('corpInquries', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid corp inqury', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('corpInqury', $this->CorpInqury->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->CorpInqury->create();
			if ($this->CorpInqury->save($this->data)) {
				$this->Session->setFlash(__('The corp inqury has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The corp inqury could not be saved. Please, try again.', true));
			}
		}
		$inquiries = $this->CorpInqury->Inquiry->find('list');
		$corporations = $this->CorpInqury->Corporation->find('list');
		$this->set(compact('inquiries', 'corporations'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid corp inqury', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->CorpInqury->save($this->data)) {
				$this->Session->setFlash(__('The corp inqury has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The corp inqury could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->CorpInqury->read(null, $id);
		}
		$inquiries = $this->CorpInqury->Inquiry->find('list');
		$corporations = $this->CorpInqury->Corporation->find('list');
		$this->set(compact('inquiries', 'corporations'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for corp inqury', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->CorpInqury->delete($id)) {
			$this->Session->setFlash(__('Corp inqury deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Corp inqury was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
	function backstage_index() {
		$this->CorpInqury->recursive = 0;
		$this->set('corpInquries', $this->paginate());
	}

	function backstage_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid corp inqury', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('corpInqury', $this->CorpInqury->read(null, $id));
	}

	function backstage_add() {
		if (!empty($this->data)) {
			$this->CorpInqury->create();
			if ($this->CorpInqury->save($this->data)) {
				$this->Session->setFlash(__('The corp inqury has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The corp inqury could not be saved. Please, try again.', true));
			}
		}
		$inquiries = $this->CorpInqury->Inquiry->find('list');
		$corporations = $this->CorpInqury->Corporation->find('list');
		$this->set(compact('inquiries', 'corporations'));
	}

	function backstage_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid corp inqury', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->CorpInqury->save($this->data)) {
				$this->Session->setFlash(__('The corp inqury has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The corp inqury could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->CorpInqury->read(null, $id);
		}
		$inquiries = $this->CorpInqury->Inquiry->find('list');
		$corporations = $this->CorpInqury->Corporation->find('list');
		$this->set(compact('inquiries', 'corporations'));
	}

	function backstage_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for corp inqury', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->CorpInqury->delete($id)) {
			$this->Session->setFlash(__('Corp inqury deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Corp inqury was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
